import os
from building import *

cwd = GetCurrentDir()

Import('asenv')
ASROOT = asenv['ASROOT']
BDIR = asenv['BDIR']
objs = []

asenv.Append(CPPDEFINES='configTOTAL_HEAP_SIZE=0x800000')
asenv.Append(CPPDEFINES='PAGE_SIZE=0x1000')
asenv.Append(CPPDEFINES='OS_TICKS_PER_SECOND=1000')
asenv.Append(CPPDEFINES='USECONDS_PER_TICK=10000')
if(not IsPlatformWindows()):
    asenv.Append(CPPDEFINES='ENABLE_SHELL_ECHO_BACK')

lds = '%s/script/linker-app.lds'%(cwd)
asenv.Append(LINKFLAGS='-static -T %s'%(lds))
if(not IsPlatformWindows()):
    asenv.Append(LINKFLAGS='-Map %s/x86.map'%(BDIR))

MODULES = ['ECUM','SCHM','MCU','DET',
           'CLIB_ASHEAP','CLIB_MISCLIB',
           'CLIB_STDIO_PRINTF','CLIB_NEWLIB',
           'SHELL','CLIB_STRTOK_R',
           'CLIB_MBOX','CLIB_QSORT',
           'PCI',
           'CAN','CANIF','PDUR','COM','COMM','CANTP','CANNM',
           'DCM','CANNM','CANSM','NM','OSEKNM','XCP',
           'SOAD','DOIP','LWIP','FTP','SD',
           'ASKAR','PTHREAD','PTHREAD_CLEANUP','PTHREAD_SIGNAL',
           'FATFS','FATFS_DRV','LIBELF','LIBDL','VFS','DEV',
           'COMMONXML'
           ]

ARCH='x86'
arch='x86'

if(asenv['MODULES'] is None):
    asenv['MODULES'] = MODULES
else:
    MODULES = asenv['MODULES']

asenv['ARCH'] = ARCH
asenv['arch'] = arch

if('run' in COMMAND_LINE_TARGETS):
    qemu = Qemu()
    target = '%s/release/%s/TINIX.IMG'%(ASROOT,asenv['RELEASE'])
    qemu.Run('-fda %s -boot a -m 64M'%(target))

asenv.Append(CPPPATH=['%s/../board.posix/common'%(cwd)])

if('MCU' in MODULES):
    objs += Glob('%s/../board.posix/common/Mcu*.c'%(cwd))

if('EEP' in MODULES):
    objs += Glob('%s/../board.posix/common/Eep*.c'%(cwd))

if('FLS' in MODULES):
    objs += Glob('%s/../board.posix/common/Fls*.c'%(cwd))

if('RTTHREAD' in MODULES):
    asenv.Append(CPPDEFINES=['RT_HEAP_SIZE=0x800000','__x86__'])

asenv.Append(CPPDEFINES=['OS_STK_SIZE_SCALER=2'])

Return('objs')
